package com.wsz.controller;

import com.wsz.bean.User;
import com.wsz.dao.UserDaoIpml;
import com.wsz.view.View;

/**
 * @author wsz
 */
public class Control {
    public static void main(String[] args) {
        while (true) {
//      给用户展示登陆页面
            User user = View.indexView();
            UserDaoIpml userDaoIpml = new UserDaoIpml();
            int type = userDaoIpml.login(user);
            switch (type) {
                case -1:
                    // 登陆失败
                    System.out.println("输入有误，请重新输入！");
                    break;
                case 1:
                    // 管理员权限登陆成功
                    System.out.println("恭喜管理员登陆成功");
                    managerServer();
                    break;
                case 2:
                    // 学生权限登陆成功
                    System.out.println("恭喜学生登陆成功");
                    studentServer();
                default:
                    break;
            }
        }
    }

    private static void managerServer() {
        UserDaoIpml userDaoIpml = new UserDaoIpml();
        while (true) {
//展示管理员菜单视图
            int item = View.managerMenuView();
            boolean flag;
            switch (item) {
                case 0:
                    // 退出
                    System.exit(-1);
                    break;
                case 1:
                    // 添加学生信息
                    User adduser = View.addMenuView();
                    flag = userDaoIpml.insert(adduser);
                    System.out.println(flag?"add success":"add fail");
                    break;
                case 2:
                    // 删除学生信息
                    String uname = View.deleteMenuView();
                    flag = userDaoIpml.delete(uname);
                    System.out.println(flag?"delete success":"delete fail");
                    break;
                case 3:
                    // 修改学生信息
                    User updateuser = View.updateMenuView();
                    flag = userDaoIpml.update(updateuser);
                    System.out.println(flag?"update success":"update fail");
                    break;
                case 4:
                    // 查询学生信息
                    String uname1 = View.selectMenuView();
                    User selectedUser = userDaoIpml.select(uname1);
                    View.printUser(selectedUser);
                    break;
                default:
                    break;
            }
        }
    }

    private static void studentServer() {

    }

}
